package fr.louloutes.lolshooter.engine.objects;

import java.util.ArrayList;
import java.util.List;

import fr.louloutes.lolshooter.engine.sprites.LolSprite;

import android.graphics.Rect;

/**
 * Class GameObjet: abstract class above all object in the game
 * 
 * @author Louloute
 * 
 */
public abstract class GameObject
{
	private LolSprite sprite;
	private double x = 0;
	private double y = 0;

	/**
	 * Constructor with initializations
	 * 
	 * @param sprite
	 */
	public GameObject( LolSprite sprite )
	{
		this.sprite = sprite;
	}

	/**
	 * Get X position of the object
	 * 
	 * @return
	 */
	public double getX()
	{
		return x;
	}

	/**
	 * Get Y position of the object
	 * 
	 * @return
	 */
	public double getY()
	{
		return y;
	}

	/**
	 * Set current position
	 * 
	 * @param x
	 * @param y
	 */
	public void setPosition( double x, double y )
	{
		this.x = x;
		this.y = y;
		sprite.setCenter( ( int ) x, ( int ) y );
	}

	/**
	 * Get object sprite
	 * 
	 * @return
	 */
	public LolSprite getSprite()
	{
		return sprite;
	}

	/**
	 * Get objects in param list colliding with current object
	 * 
	 * @param group
	 * @return
	 */
	public List<GameObject> collide( ObjectGroup<? extends GameObject> group )
	{
		List<GameObject> result = new ArrayList<GameObject>();
		for ( GameObject gObject : group )
		{
			if ( this.collide( gObject ) )
			{
				result.add( gObject );
			}
		}
		return result;
	}

	/**
	 * Is a particular object in collision with current object ?
	 * 
	 * @param gObject
	 * @return
	 */
	public boolean collide( GameObject gObject )
	{
		return this.sprite.collide( gObject.getSprite() );
	}

	abstract public void move( long elapsedTime, Rect frameRect );
}
